#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include "ms_get.h"

void set_signal_handlers(void);
void exit_ms_test(int a);

int
main(void)
{
	int x, y, x_old, y_old;

	set_signal_handlers();

	ms_get_info();
	x_old = ms_get_x();
	y_old = ms_get_y();

	while(1) 
	{
		ms_get_info();
		x = ms_get_x();
		y = ms_get_y();

		if(x != x_old || y != y_old)
		{
			system("clr");
			printf("\n\nX = %2d - Y = %2d\t", x, y);

			x_old = x;
			y_old = y;

			/*if (ms_get_left())
				printf("LEFT CLICK!!!\t");
			
			if(ms_get_right())
				printf("RIGHT CLICK!!!\t");*/

			printf("\n"); 
		}
	}

	return 0;
}

void
set_signal_handlers(void)
{
	signal(SIGINT, exit_ms_test);
	signal(SIGTERM, exit_ms_test);
	signal(SIGQUIT, exit_ms_test);
	signal(SIGALRM, exit_ms_test);
}

void
exit_ms_test(int a)
{
	exit(0);
}